package com.ruoyi.web.controller.rgpp;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.rgpp.domain.JmrypStudents;
import com.ruoyi.rgpp.service.IJmrypStudentsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 发布简历Controller
 * 
 * @author ruoyi
 * @date 2022-06-15
 */
@Controller
@RequestMapping("/rgpp/ypstudents")
public class JmrypStudentsController extends BaseController
{
    private String prefix = "rgpp/ypstudents";

    @Autowired
    private IJmrypStudentsService jmrypStudentsService;

    @RequiresPermissions("rgpp:ypstudents:view")
    @GetMapping()
    public String ypstudents()
    {
        return prefix + "/ypstudents";
    }

    /**
     * 查询发布简历列表
     */
    @RequiresPermissions("rgpp:ypstudents:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JmrypStudents jmrypStudents)
    {
//        startPage();
//        List<JmrypStudents> list = jmrypStudentsService.selectJmrypStudentsList(jmrypStudents);
//        return getDataTable(list);

        SysUser user = getSysUser();
        String card=user.getLoginName();
        List<JmrypStudents> list=new ArrayList<>();
        if (user.getUserId()==1){
            startPage();
            list = jmrypStudentsService.selectJmrypStudentsList(jmrypStudents);

        }else {
            jmrypStudents.setCard(card);
            startPage();
            list=jmrypStudentsService.selectJmrypStudentsList(jmrypStudents);
        }
        return getDataTable(list);
    }

    /**
     * 导出发布简历列表
     */
    @RequiresPermissions("rgpp:ypstudents:export")
    @Log(title = "发布简历", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JmrypStudents jmrypStudents)
    {
        List<JmrypStudents> list = jmrypStudentsService.selectJmrypStudentsList(jmrypStudents);
        ExcelUtil<JmrypStudents> util = new ExcelUtil<JmrypStudents>(JmrypStudents.class);
        return util.exportExcel(list, "发布简历数据");
    }

    /**
     * 新增发布简历
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存发布简历
     */
    @RequiresPermissions("rgpp:ypstudents:add")
    @Log(title = "发布简历", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JmrypStudents jmrypStudents)
    {
        return toAjax(jmrypStudentsService.insertJmrypStudents(jmrypStudents));
    }

    /**
     * 修改发布简历
     */
    @RequiresPermissions("rgpp:ypstudents:edit")
    @GetMapping("/edit/{card}")
    public String edit(@PathVariable("card") String card, ModelMap mmap)
    {
        JmrypStudents jmrypStudents = jmrypStudentsService.selectJmrypStudentsByCard(card);
        mmap.put("jmrypStudents", jmrypStudents);
        return prefix + "/edit";
    }

    /**
     * 修改保存发布简历
     */
    @RequiresPermissions("rgpp:ypstudents:edit")
    @Log(title = "发布简历", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JmrypStudents jmrypStudents)
    {
        return toAjax(jmrypStudentsService.updateJmrypStudents(jmrypStudents));
    }

    /**
     * 删除发布简历
     */
    @RequiresPermissions("rgpp:ypstudents:remove")
    @Log(title = "发布简历", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jmrypStudentsService.deleteJmrypStudentsByCards(ids));
    }
}
